<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
    
	<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
	<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>
<div class="panel" style="height: 540px; overflow: auto;">
	<div class="panel-body pan" >
		<div class="row" style="margin-bottom: 10px;">
		<input id="balance" type="hidden" class="form-control" value="0" />
		<input id="payment" type="hidden" class="form-control" value="0" />
			<div class="col-lg-6"
				style="width: 400px; float:left;display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">用户名
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="username" type="text" class="form-control" onchange="verifyName(this.value)" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6" style="width: 400px; float:left; margin-left:-20px; display:inline;" id="passwordDiv">
				<label for="inputUsername" class="col-md-3 control-label">密码
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="password" type="password" class="form-control" value="" />
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">机构名称
				<span class='require' id="yonghu">*</span></label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="realname" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-left:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">昵称
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nickname" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left;display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">头像</label>
				<div class="col-md-9">
					<div >
						<div style= "display:inline " id="single_"></div>
							<div style="display:inline " id="single"></div>
							<input type="button" class="btn btn-primary" style="width: 70px;height: 30px;padding: 0;background-color: #4cae4c;border-color: #4cae4c;" onclick="upImages()" value="上传图片"  />
							<textarea id="uploadImage" name="uploadImage"></textarea>
							<input id="avatarImg" type="hidden" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left;margin-left:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">用户类型
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="type" class="form-control">
							<option value="1">机构用户</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">联系电话
				<span class='require'></span></label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="telephone" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-left:-20px;display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">手机号
				<span class='require'></span></label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="mobilephone" type="text" class="form-control" />
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px;display:inline;margin-bottom: 10px;">
				<label for="inputUsername" class="col-md-3 control-label" >登录方式
					</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="loginMode" class="form-control" onchange="gradeChange()">
							<option value="0">用户名和密码</option>
							<option value="1">ip自动登录</option>
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;margin-bottom: 10px;">
				<label for="inputUsername" class="col-md-3 control-label">状态</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="status" class="form-control">
							<option value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;margin-bottom: 10px;">
				<label for="inputUsername" class="col-md-3 control-label">联系人</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="contact" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;margin-bottom: 10px;">
				<label for="inputUsername" class="col-md-3 control-label">邮箱</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="email" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;margin-bottom: 10px;">
				<label for="inputUsername" class="col-md-3 control-label">地址
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="address" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">秘钥</label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="keys" type="text"  class="form-control" disabled="true" /> 
						<span class="input-group-btn">
						<button onclick="createKeys()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">生成秘钥</button>
						</span> 
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-12" style=" float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-xs-12 control-label">账号ip段<span class='require'>*</span>
				</label>
				<input id="ips" name="ips" type="hidden" class="form-control" value="1;"/>
				<div class="col-xs-3">
					<div class="input-icon" id="startDiv">
						<input id="ipStart_1" name="ipStart_1" type="text" class="form-control" value="" placeholder="起始IP" style="margin-top: 10px;"/>
					</div>
				</div>
				<div class="col-xs-1" style="line-height: 34px;">
					<div class="input-icon" id="ipkey">
						<p style="margin-top: 10px;" id="ipk_1">至</p>
					</div>
				</div>
				<div class="col-xs-3">
					<div class="input-icon" id="endDiv">
						<input id="ipEnd_1" name="ipEnd_1" type="text" class="form-control" value="" placeholder="截止IP" style="margin-top: 10px;"/>
					</div>
				</div>
				<div class="col-xs-2">
		               <button type="button" data-toggle="dropdown" style="margin-top: 10px;" class="btn btn-success dropdown-toggle" onclick="addIp()">+</button>
		               <button type="button" data-toggle="dropdown" style="margin-top: 10px;" class="btn btn-success dropdown-toggle" onclick="deleteIp()">-</button>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">有效期</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="validity" type="text" class="form-control" value="" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;margin-bottom: 10px;">
				<label for="inputUsername" class="col-md-3 control-label">备注</label>
				<div class="col-md-9">
						<div class="input-icon">
							<textarea rows="2" cols="10" style="color:#999999" id="remarks"
								type="text" class="form-control"></textarea>
						</div>
				</div>
			</div>
		</div>
		
	</div>

</div>
<?} ?>
<script>
	function gradeChange() {
			var objS = document.getElementById("loginMode");
			var gradeid = objS.options[objS.selectedIndex].value;
			
			if(gradeid==0){
				$("#showSeparator").hide();
			}else{
				$("#showSeparator").show();;
			}
		}
	
	var index1 = window.parent.getlay();
	var _editor;
	$(function() {
		gradeChange();
		if(index1 != 0){
			$.ajax({
			type : "post",
			url : "./listUpdate.do",
			data : {
				"id" : index1,
			},
			dataType : "json",
			async : false,
			success : function(data) {
				$("#username").val(data[0].member.username);
				$("#password").val(data[0].member.password);
				 document.getElementById('password').disabled = true;
				 document.getElementById('passwordDiv').style.display="none";
				$("#nickname").val(data[0].member.nickname);
				$("#realname").val(data[0].member.realname);
				$("#type").val(data[0].member.type);
				$("#createTime").val(data[0].member.createTime);
				$("#createIpAddress").val(data[0].member.createIpAddress);
				$("#avatarImg").val(data[0].member.avatarImg);
				$("#single").html("<img src='"+data[0].member.avatarImg+"' width='30' height='30'/>");
				$("#email").val(data[0].member.email);
				$("#status").val(data[0].member.status);
				$("#mobilephone").val(data[0].member.mobilephone);
				$("#loginMode").val(data[0].member.loginMode);
				$("#balance").val(data[0].member.balance);
				$("#payment").val(data[0].member.payment);
				$("#keys").val(data[0].member.keys);
				$("#address").val(data[0].member.address);
				$("#telephone").val(data[0].member.telephone);
				$("#validity").val(data[0].member.validity);
				$("#contact").val(data[0].member.contact);
				$("#remarks").val(data[0].member.remarks);
				for(var i=0;i<data[0].ipLoginNumberList.length;i++){	
				 	var ips = $("#ips").val();
					var ipCount = ips.substr(0,ips.length-1);
					var ipLength=ipCount.length;
					if(i == '0'){
						$("#startDiv").html('<input id="ipStart_1" name="ipStart_'+(ipLength+1)+'" type="text" class="form-control" value="'+data[0].ipLoginNumberList[i].startIpAddressNumber+'" placeholder="起始IP" style="margin-top: 10px;"/>');
						$("#ipkey").html('<p style="margin-top: 10px;" id="ipk_1">至</p>');
						$("#endDiv").html('<input id="ipEnd_1" name="ipEnd_'+(ipLength+1)+'" type="text" class="form-control" value="'+data[0].ipLoginNumberList[i].endIpAddressNmber+'" placeholder="截止IP" style="margin-top: 10px;"/>');
					}else{
						$("#startDiv").append('<input id="ipStart_'+(ipLength+1)+'" name="ipStart_'+(ipLength+1)+'" type="text" class="form-control" value="'+data[0].ipLoginNumberList[i].startIpAddressNumber+'" placeholder="起始IP" style="margin-top: 10px;"/>');
						$("#ipkey").append('<p style="margin-top: 10px;" id="ipk_'+(ipLength+1)+'">至</p>');
						$("#endDiv").append('<input id="ipEnd_'+(ipLength+1)+'" name="ipEnd_'+(ipLength+1)+'" type="text" class="form-control" value="'+data[0].ipLoginNumberList[i].endIpAddressNmber+'" placeholder="截止IP" style="margin-top: 10px;"/>');
						$("#ips").val(ips+(ipLength+1)+";");
					}
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
		}
		 _editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#avatarImg").val(urlPath);
						$("#single").html("<img src='"+urlPath+"' width='30' height='30' />");
	  	 			}
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	
		   	 });
	   }); 
	});
	//上传图片
	function upImages() {
		var myFiles = _editor.getDialog("insertimage");
	  		myFiles.open();
	   
	}
	function Page() {
		if ($.trim($("#username").val()).length < 1) {
			alert('用户名不能为空！');
			return null;
		}
		if ($.trim($("#password").val()).length < 1) {
			alert('密码不能为空！');
			return null;
		}else{
			var reg =new RegExp("[\u4e00-\u9fa5]");
			if(reg.test($("#password").val())){
		      	alert('密码只可由数字和字母组成！');
		      	$("#password").val("");
				return null;
		    }
		}
		
		if ($.trim($("#realname").val()).length < 1) {
			alert('机构名称不能为空！');
			return null;
		}
/* 		if ($.trim($("#mobilephone").val()).length < 1) {
			alert('手机号不能为空！');
			return null;
		} */
		if ($.trim($("#status").val()).length < 1) {
			alert('请选择状态！');
			return null;
		}
		if ($.trim($("#loginMode").val()).length < 1) {
			alert('请选择登录方式！');
			return null;
		}
		/*
		if ($.trim($("#validity").val()).length < 1) {
			alert('请选择有效期！');
			return null;
		}
		*/
		var ips = $("#ips").val();
		var ipCount = ips.substr(0,ips.length-1);
		var scores=ipCount.split(";");
		var ip='';
		for(var i=0;i<scores.length;i++){
			 	ip += $("#ipStart_"+scores[i]).val()+"-"+$("#ipEnd_"+scores[i]).val()+";";
		}
		if ("-;" == ip) {
			alert('ip段不能为空！');
			return null;
		}
		
		var text=$.trim($("#email").val()); //    
       	var re =/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
       	if ($.trim($("#email").val()).length >0) {
			if (!re.test(text)) {
				alert('邮箱格式不正确！');
				return null;
			}
		}
		
		var telephonetext=$.trim($("#mobilephone").val()); //    
       	var telephonere =/^[1][3,4,5,7,8][0-9]{9}$/;
       	if ($.trim($("#mobilephone").val()).length >0) {
			if (!telephonere.test(telephonetext)) {
				alert('手机号格式不正确！');
				return null;
			}
		}
		//添加
		$.ajax({
			type : "post",
			url : "./listAddUpdate.do",
			data : {
				"id" : index1,
				"username" : $("#username").val(),
				"password" : $("#password").val(),
				"nickname" : $("#nickname").val(),
				"realname" : $("#realname").val(),
				"mobilephone" : $("#mobilephone").val(),
				"createIpAddress" : $("#createIpAddress").val(),
				"email" : $("#email").val(),
				"avatarImg" : $("#avatarImg").val(),
				"createTime" : $("#createTime").val(),
				"status" : $("#status").val(),
				"type" : $("#type").val(),
				"ipSegment" : ip,
				"loginMode" : $("#loginMode").val(),
				"balance" : $("#balance").val(),
				"payment" : $("#payment").val(),
				"keys" : $("#keys").val(),
				"address" : $("#address").val(),
				"telephone" : $("#telephone").val(),
				"validity" : $("#validity").val(),
				"contact" : $("#contact").val(),
				"remarks" : $("#remarks").val(),
			
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	
	function newdate() {
		$.getJSON('./newDate.do', {}, function(res) {
			$("#createTime").val(res.date);
		});
	};
	
	function addIp(){
		var ips = $("#ips").val();
		var ipCount = ips.substr(0,ips.length-1);
		var ipLength=ipCount.length;
		$("#startDiv").append('<input id="ipStart_'+(ipLength+1)+'" name="ipStart_'+(ipLength+1)+'" type="text" class="form-control" value="" placeholder="起始IP" style="margin-top: 10px;"/>');
		$("#ipkey").append('<p style="margin-top: 10px;" id="ipk_'+(ipLength+1)+'">至</p>');
		$("#endDiv").append('<input id="ipEnd_'+(ipLength+1)+'" name="ipEnd_'+(ipLength+1)+'" type="text" class="form-control" value="" placeholder="截止IP" style="margin-top: 10px;"/>');
		$("#ips").val(ips+(ipLength+1)+";");
	}
	function deleteIp(){
		var ips = $("#ips").val();
		var ipCount = ips.substr(0,ips.length-1);
		var scores=ipCount.split(";");
		var deleteDiv=scores[scores.length-1];
		if(deleteDiv != '1'){
   			document.getElementById("ipStart_"+deleteDiv).parentNode.removeChild(document.getElementById("ipStart_"+deleteDiv));
   			document.getElementById("ipk_"+deleteDiv).parentNode.removeChild(document.getElementById("ipk_"+deleteDiv));
   			document.getElementById("ipEnd_"+deleteDiv).parentNode.removeChild(document.getElementById("ipEnd_"+deleteDiv));
   			var countValue = '';
   			for(var i=0;i<scores.length-1;i++){
			 	countValue += scores[i]+";";
			}
			$("#ips").val(countValue);
   		}else{
	   		$("#ipStart_"+deleteDiv).val("");
	   		$("#ipEnd_"+deleteDiv).val("");
   		}
	}
	function createKeys(){
		$.ajax({
			type : "post",
			url : "createKeys.do",
			dataType : "json",
			success : function(data) {
				$("#keys").val(data[0].keys);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	 //验证用户名是否重复
 function verifyName(memberName){
	$.ajax({
		type : "post",
		url : "verifyMemberName.do",
		data : {
			"memberName" : memberName,
			"type" : 1,
		},
		async : false,
		dataType : "json",
		success : function(data) {
			if(data[0].count != '0'){
				$("#username").val("");
				layer.msg('用户名已存在!请重新输入！');
			}
		},
		error : function(data) {
			alert("请求失败");
		}
	});
 }
</script>
